<template>
  <div class="app-container">
    <div class="search-container">
      <div class="search-wrapper">
        <div class="debenture-search">
          <el-form ref="transactionControlSearchVo" :model="transactionControlSearchVo" :rules="transactionControlSearchVoRules" label-width="80px" class="search-from">
            <el-form-item >
              <el-col :span="11">
                <el-form-item label="帐户" prop="transactionAccount">
                  <el-input v-model="transactionControlSearchVo.transactionAccount" placeholder="帐户" style="width: 60%;"/>
                </el-form-item>
              </el-col>
              <el-col :span="11">
                <el-form-item label="日期" prop="transactionDate">
                  <el-date-picker v-model="transactionControlSearchVo.transactionDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 70%;"/>
                </el-form-item>
              </el-col>
            </el-form-item>
          </el-form>
          <el-button class="sreach-button" type="primary" @click="search('transactionControlSearchVo')">搜索</el-button>
        </div>
      </div>
    </div>
    <el-table

      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="transactionAccount"
        label="帐户"
        width="180"/>
      <el-table-column
        prop="debentureCode"
        label="债券代码"
        width="180"/>
      <el-table-column
        prop="debentureName"
        label="债券名称">
        北京
      </el-table-column>
      <el-table-column
        label="交易方向">
        <template slot-scope="scope">
          <div v-if="scope.row.transactionDirection == 1 " class="bottom-wrapper mt60">
            <el-button class="button-wrapper">
              <div class="v-button white" >买入</div>
            </el-button>
          </div>
          <div v-if="scope.row.transactionDirection == 2 " class="bottom-wrapper mt60">
            <el-button class="button-wrapper">
              <div class="v-button white">卖出</div>
            </el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="transactionDate"
        label="交易日期"/>
      <el-table-column
        prop="priceDeviation"
        label="交易偏移度">
        北京
      </el-table-column>
      <el-table-column
        prop="address"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleClick(scope.row)" >查看</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page.sync="page"
      :total="total"
      :page-size="limit"
      class="pagination"
      layout="prev, pager, next"
      @current-change="handleCurrentChange"/>
    </div>
</template>

<script>
import configurationtable from '@/api/configurationtable'
import { getToken } from '@/utils/auth'

export default {
  data() {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      transactionControlSearchVo: {
        transactionAccount: '',
        transactionDate: ''
      },

      tableData: [],
      page: 1, // 当前页
      limit: 10, // 每页个数
      total: 1 // 总页码
    }
  },
  created() {
    this.getByPage()
  },
  methods: {
    onSubmit() {
      this.$message('submit!')
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    },
    handleCurrentChange(val){
      this.page = val;
      this.getByPage();
    },
    search(formName) {
        this.$refs[formName].validate((valid)=>{
          if(valid){
            configurationtable.pageBySearch(this.page, this.limit, this.transactionControlSearchVo).then(response => {
            this.tableData = response.data.records
            this.total = response.data.total
            })
          }
        })
    },
    getByPage() {
      configurationtable.page(this.page, this.limit).then(response => {
        this.tableData = response.data.records
        this.total = response.data.total
      })
    }
  }
}
</script>

<style scoped>
.search-input{
  margin-left: 900px;
}
.search-from{
  margin-left: 100px;
}
.sreach-button{
  margin-left: 550px;
}
</style>
